package com.crazyread.imple;

import com.crazyread.dao.CommentMapper;
import com.crazyread.dao.StatisticMapper;
import com.crazyread.model.domain.Comment;
import com.crazyread.model.domain.Statistic;
import com.crazyread.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class CommentServiceImpl implements CommentService {
    @Autowired
    CommentMapper commentMapper;
    @Autowired
    StatisticMapper statisticMapper;

    @Override
    public List<Comment> selAllComment(Integer bookId) {
        List<Comment> commentList = commentMapper.getCommentList(bookId);
        return commentList;
    }

    @Override
    public void pushComment(Comment comment) {
        commentMapper.pushComment(comment);
        Statistic statistic = statisticMapper.selectStatisticByBid(comment.getBookId());
        statistic.setCommentNum(statistic.getCommentNum()+1);
        statisticMapper.updateBookComNum(statistic);

    }


}
